﻿using Basic.UserFormService.PageControl.Calculate.Extend;
using Dm.util;
using Flee.PublicTypes;

namespace Basic.UserFormService.PageControl.Calculate
{
    internal class CalculateValue
    {
        private static readonly ExpressionContext _Context;
        static CalculateValue ()
        {
            _Context = new ExpressionContext();
            _Context.Options.RealLiteralDataType = RealLiteralDataType.Decimal;
            _Context.Imports.AddType(typeof(TimeExtend));
        }

        public static object Calculate ( string formula )
        {
            formula = formula.replace("'", "\"");
            IDynamicExpression expre = _Context.Clone().CompileDynamic(formula);
            return expre.Evaluate();
        }
    }
}
